'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate', 'validate.en','date', 'date.zh'], function($) {
  return {
    
    init : function(data) {
      this.initPage(data);
      this.processingActive();
    },
    
    initPage: function(data) {
      
      $('[data-toggle="popover"]').popover();
      $('[data-toggle="tooltip"]').tooltip();
      $(".timeline-overflow").css("height", $(document).height()-300);
      
      var finalStart1 = new Date(data.consolidationDay + ' 12:45:00')
      var finalEnd1 = new Date(data.consolidationDay + ' 15:45:00')
      $("#calibration-two").data("start", finalStart1.getTime());
      $("#calibration-two").data("end", finalEnd1.getTime());
      
      var time = $.now();
      $(".timeline-content .alink").removeClass("active");
      $(".timeline-content .alink").each(function () {
        if ( parseInt(time) >= parseInt($(this).data("start")) && time <= parseInt($(this).data("end")) ) {
          $(this).addClass("active");
        }
      })
      
    },
    
    processingActive : function ( ) {
      
      setInterval(function ( ) {
        
        var time = $.now();
        $(".timeline-content .alink").removeClass("active");
        $(".timeline-content .alink").each(function ( ) {
          if ( time >= $(this).data("start") && time <= $(this).data("end") ) {
            $(this).addClass("active");
          }
        })

      }, 30000);
      
    }
    
  }
})
